package org.grow.ceto.controller;

import io.swagger.annotations.ApiImplicitParam;
import org.grow.ceto.entity.Profession;
import org.grow.ceto.exception.CetoException;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Stream;

/**
 * @Author: xwg
 * @CreateDate: 21-8-25
 */

@RestController
@RequestMapping("/ceto/common")
public class CommonController {

    @GetMapping("/professionTypes")
    public Stream<Map<String, Object>> professionTypes() {
        return Arrays.stream(Profession.values())
                .map(x -> {
                    Map<String, Object> obj = new TreeMap<>();
                    obj.put("text", x.getText());
                    obj.put("value", x.name());
                    obj.put("index", x.ordinal());
                    return obj;
                });
    }
    @ApiImplicitParam(dataTypeClass = Integer.class,paramType = "path",defaultValue = "1")
    @GetMapping("/unixTime/{flag}")
    public Long unixTime(@PathVariable("flag") Integer flag){
        if (flag<=0){
            throw new CetoException("unix时间异常",CetoException.COMMONEXC+1);
        }
        return System.currentTimeMillis();
    }
    @ApiImplicitParam(dataTypeClass = Integer.class,paramType = "path")
    @GetMapping("/isoTime/{flag}")
    public LocalDateTime isoTime(@PathVariable("flag") Integer flag){
        if (flag<=0){
            throw new CetoException("iso时间异常",CetoException.COMMONEXC+2);
        }
        return LocalDateTime.now();
    }
 }
